from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-13 14:06:59.304287
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 13, May, 2022
Time: 14:07:04
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2706
Nobs: 655.000 HQIC: -49.6479
Log likelihood: 8063.29 FPE: 2.15994e-22
AIC: -49.8868 Det(Omega_mle): 1.88460e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.321207 0.061066 5.260 0.000
L1.Burgenland 0.105114 0.038984 2.696 0.007
L1.Kärnten -0.109540 0.020434 -5.361 0.000
L1.Niederösterreich 0.195454 0.081377 2.402 0.016
L1.Oberösterreich 0.123378 0.080308 1.536 0.124
L1.Salzburg 0.257031 0.041408 6.207 0.000
L1.Steiermark 0.043888 0.054335 0.808 0.419
L1.Tirol 0.101702 0.043784 2.323 0.020
L1.Vorarlberg -0.063074 0.038796 -1.626 0.104
L1.Wien 0.030380 0.071082 0.427 0.669
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.049659 0.130361 0.381 0.703
L1.Burgenland -0.032452 0.083221 -0.390 0.697
L1.Kärnten 0.040584 0.043622 0.930 0.352
L1.Niederösterreich -0.187827 0.173719 -1.081 0.280
L1.Oberösterreich 0.449736 0.171437 2.623 0.009
L1.Salzburg 0.284649 0.088395 3.220 0.001
L1.Steiermark 0.107616 0.115991 0.928 0.354
L1.Tirol 0.311552 0.093468 3.333 0.001
L1.Vorarlberg 0.022034 0.082821 0.266 0.790
L1.Wien -0.037396 0.151743 -0.246 0.805
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187155 0.031347 5.970 0.000
L1.Burgenland 0.089650 0.020011 4.480 0.000
L1.Kärnten -0.007659 0.010489 -0.730 0.465
L1.Niederösterreich 0.253942 0.041773 6.079 0.000
L1.Oberösterreich 0.155530 0.041224 3.773 0.000
L1.Salzburg 0.042332 0.021256 1.992 0.046
L1.Steiermark 0.024570 0.027891 0.881 0.378
L1.Tirol 0.084449 0.022475 3.757 0.000
L1.Vorarlberg 0.053547 0.019915 2.689 0.007
L1.Wien 0.117720 0.036488 3.226 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111573 0.031445 3.548 0.000
L1.Burgenland 0.045813 0.020074 2.282 0.022
L1.Kärnten -0.014054 0.010522 -1.336 0.182
L1.Niederösterreich 0.182529 0.041904 4.356 0.000
L1.Oberösterreich 0.328001 0.041353 7.932 0.000
L1.Salzburg 0.101457 0.021322 4.758 0.000
L1.Steiermark 0.109920 0.027979 3.929 0.000
L1.Tirol 0.096223 0.022546 4.268 0.000
L1.Vorarlberg 0.059827 0.019978 2.995 0.003
L1.Wien -0.022147 0.036603 -0.605 0.545
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114800 0.058507 1.962 0.050
L1.Burgenland -0.043758 0.037350 -1.172 0.241
L1.Kärnten -0.046295 0.019578 -2.365 0.018
L1.Niederösterreich 0.141456 0.077966 1.814 0.070
L1.Oberösterreich 0.160742 0.076942 2.089 0.037
L1.Salzburg 0.282038 0.039672 7.109 0.000
L1.Steiermark 0.055795 0.052057 1.072 0.284
L1.Tirol 0.165358 0.041949 3.942 0.000
L1.Vorarlberg 0.095874 0.037170 2.579 0.010
L1.Wien 0.076241 0.068103 1.119 0.263
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059949 0.046149 1.299 0.194
L1.Burgenland 0.031515 0.029461 1.070 0.285
L1.Kärnten 0.051515 0.015443 3.336 0.001
L1.Niederösterreich 0.207742 0.061498 3.378 0.001
L1.Oberösterreich 0.317040 0.060691 5.224 0.000
L1.Salzburg 0.041030 0.031293 1.311 0.190
L1.Steiermark 0.006512 0.041062 0.159 0.874
L1.Tirol 0.130812 0.033089 3.953 0.000
L1.Vorarlberg 0.065338 0.029319 2.228 0.026
L1.Wien 0.089343 0.053719 1.663 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174858 0.055387 3.157 0.002
L1.Burgenland 0.004924 0.035359 0.139 0.889
L1.Kärnten -0.065170 0.018534 -3.516 0.000
L1.Niederösterreich -0.097813 0.073809 -1.325 0.185
L1.Oberösterreich 0.204331 0.072839 2.805 0.005
L1.Salzburg 0.054112 0.037557 1.441 0.150
L1.Steiermark 0.242070 0.049282 4.912 0.000
L1.Tirol 0.500770 0.039712 12.610 0.000
L1.Vorarlberg 0.058334 0.035189 1.658 0.097
L1.Wien -0.073789 0.064472 -1.145 0.252
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146633 0.061403 2.388 0.017
L1.Burgenland 0.004559 0.039199 0.116 0.907
L1.Kärnten 0.060521 0.020547 2.946 0.003
L1.Niederösterreich 0.183618 0.081826 2.244 0.025
L1.Oberösterreich -0.057377 0.080751 -0.711 0.477
L1.Salzburg 0.205738 0.041636 4.941 0.000
L1.Steiermark 0.134611 0.054635 2.464 0.014
L1.Tirol 0.067911 0.044026 1.543 0.123
L1.Vorarlberg 0.143418 0.039011 3.676 0.000
L1.Wien 0.112093 0.071475 1.568 0.117
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375603 0.036152 10.390 0.000
L1.Burgenland -0.000792 0.023079 -0.034 0.973
L1.Kärnten -0.021669 0.012097 -1.791 0.073
L1.Niederösterreich 0.212624 0.048176 4.413 0.000
L1.Oberösterreich 0.228329 0.047543 4.803 0.000
L1.Salzburg 0.038531 0.024514 1.572 0.116
L1.Steiermark -0.014805 0.032167 -0.460 0.645
L1.Tirol 0.093585 0.025921 3.610 0.000
L1.Vorarlberg 0.053983 0.022968 2.350 0.019
L1.Wien 0.036559 0.042082 0.869 0.385
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036504 0.116307 0.173370 0.142410 0.100439 0.084342 0.040068 0.210759
Kärnten 0.036504 1.000000 -0.019875 0.134775 0.052352 0.089971 0.440643 -0.060276 0.093234
Niederösterreich 0.116307 -0.019875 1.000000 0.324097 0.128499 0.284768 0.073507 0.162270 0.297519
Oberösterreich 0.173370 0.134775 0.324097 1.000000 0.220824 0.309417 0.167579 0.150725 0.251301
Salzburg 0.142410 0.052352 0.128499 0.220824 1.000000 0.130017 0.097688 0.115284 0.130084
Steiermark 0.100439 0.089971 0.284768 0.309417 0.130017 1.000000 0.138684 0.118045 0.050016
Tirol 0.084342 0.440643 0.073507 0.167579 0.097688 0.138684 1.000000 0.069853 0.146808
Vorarlberg 0.040068 -0.060276 0.162270 0.150725 0.115284 0.118045 0.069853 1.000000 0.007374
Wien 0.210759 0.093234 0.297519 0.251301 0.130084 0.050016 0.146808 0.007374 1.000000